package com.ddwl.funds.dao;

import com.ddwl.common.constant.OrderEnum;
import com.ddwl.common.dao.TkDao;
import com.ddwl.funds.dao.mapper.OrderPayMapper;
import com.ddwl.funds.dao.model.OrderPay;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * 订单支付表(OrderPay)数据处理
 *
 * @author zach
 * @since 2020-09-24 11:42:01
 */
@Repository
public class OrderPayDao  extends TkDao<OrderPayMapper, OrderPay> {


    public OrderPay getOrderPayByOrderId(String orderId){
        OrderPay orderPay = new OrderPay();
        orderPay.setOrderId(orderId);
        return selectOne(orderPay);
    }

    public OrderPay getOrderPayByTradeNo(String tradeNo){
        OrderPay orderPay = new OrderPay();
        orderPay.setTradeNo(tradeNo);
        return selectOne(orderPay);
    }

    /**
     * 查询子订单
     * @param orderId
     * @return
     */
    public List<OrderPay> getOrderPayByMasterId(String orderId){
        OrderPay orderPay = new OrderPay();
        orderPay.setMasterOrderId(orderId);
        orderPay.setIsMerge("0");
        return select(orderPay);
    }

    /**
     * 更新完成支付的订单状态
     * @param orderPayId
     * @return
     */
    public void completePayment(String orderPayId,String payAppId,String transactionId,Integer payType,String payFlowId){
        OrderPay update = new OrderPay();
        update.setId(orderPayId);
        update.setTradeNo(transactionId);
        update.setTradeStatus(OrderEnum.PayStatus.SUCCEED.getCode());
        update.setPayType(payType);
        update.setPayFlowId(payFlowId);
        update.setPayAppId(payAppId);
        updateByPrimaryKeySelective(update);
    }

    public OrderPay getOrderPay(String orderId,String phaseId,String product){
        OrderPay orderPay = new OrderPay();
        orderPay.setOrderId(orderId);
        orderPay.setPhaseId(phaseId);
        orderPay.setProduct(product);
        return selectOne(orderPay);
    }

}